<template>
    <view class="user-popup">
        <van-dialog id="van-dialog" confirm-button-color="#00BCAB" />
        <view class="distance">
            <view class="dist_s"></view>
        </view>
        <view class="con">
            <view class="user-title">
                <view style="padding: 0 35rpx; width: 104rpx; height: 104rpx">
                    <image :src="faceImageUrl ? faceImageUrl : '/assets/img/user/tx.jpg'" style="width: 100%; height: 100%" />
                </view>
                <view class="user-title-right">
                    <view style="font-size: 40rpx">{{ username }}</view>
                    <view style="font-size: 26rpx">{{ phoneNumber }}</view>
                    <view style="font-size: 26rpx">{{ plateNos }}</view>
                </view>
                <view class="setting-icon" @tap="handleusermessage">
                    <van-icon name="setting-o" />
                </view>
            </view>
            <view class="user-body">
                <view class="user-pay mycard" @tap="Gowallet">
                    <view class="user-t1">我的钱包</view>
                    <view class="user-t1-body">
                        <view class="user-t1-item">
                            <text class="user-t2">总收益</text>
                            <text class="user-t2 bold">¥{{ allMoney }}</text>
                            <text class="user-t2">元</text>
                        </view>
                        <view class="user-t2-body">
                            <view class="user-t1-item">
                                <text class="user-t2">余额</text>
                                <text class="user-t2 bold">¥{{ balance }}</text>
                                <text class="user-t2">元</text>
                            </view>
                            <view class="user-t1-item tr">
                                <text class="user-t2">已提现</text>
                                <text class="user-t2 bold">¥{{ withdrawalMoney }}</text>
                                <text class="user-t2">元</text>
                            </view>
                        </view>
                    </view>
                    <view class="card-footer-btn">
                        <view>
                            <text class="pay">支付设置</text>
                        </view>
                        <view style="text-align: right" @tap.stop.prevent="handleCash">
                            <text class="tx">去提现</text>
                        </view>
                    </view>
                </view>
                <view class="body-item" @tap="handleOrder">
                    <image src="../../static/assets/img/user/wddd.png" style="margin-right: 0; width: 34rpx; height: 34rpx" />
                    <view class="body-item-text">我的订单</view>
                    <van-icon name="arrow" size="30rpx" style="margin-right: 0; margin-left: auto" />
                </view>
                <!-- <view class="body-item" bindtap="handleoCmmunity">
                <image src="/assets/img/user/wdxq.jpg" style="margin-right: 0;width:34rpx;height:34rpx" />
                <view class="body-item-text">我的小区（发布车位）</view>
                <van-icon name="arrow" size="30rpx" style="margin-right: 0;margin-left: auto" />
            </view> -->
                <view class="body-item" @tap="messageCenter">
                    <image src="../../static/assets/img/user/xxzx.png" style="margin-right: 0; width: 34rpx; height: 34rpx" />
                    <view class="body-item-text">消息中心</view>
                    <van-icon name="arrow" size="30rpx" style="margin-right: 0; margin-left: auto" />
                </view>
                <!-- <view class="body-item" bindtap="toPlatformRules">
                <image src="/assets/img/user/ptgz.png" style="margin-right: 0;width:34rpx;height:34rpx" />
                <view class="body-item-text">平台规则</view>
                <van-icon name="arrow" size="30rpx" style="margin-right: 0;margin-left: auto" />
            </view> -->
                <view class="body-line"></view>
                <view class="body-item" style="margin-top: 0" @tap="toNormalQuestion">
                    <image src="../../static/assets/img/user/cjwt.png" style="margin-right: 0; width: 34rpx; height: 34rpx" />
                    <view class="body-item-text">常见问题</view>
                    <van-icon name="arrow" size="30rpx" style="margin-right: 0; margin-left: auto" />
                </view>
                <view class="body-line"></view>
                <!-- <view class="body-item" style="margin-top: 0" bindtap="handleSuggest">
                <image src="/assets/img/user/jyfk.png" style="margin-right: 0;width:34rpx;height:34rpx" />
                <view class="body-item-text">建议反馈</view>
                <van-icon name="arrow" size="30rpx" style="margin-right: 0;margin-left: auto" />
            </view> -->
                <view class="body-line"></view>
                <view class="body-item" style="margin-top: 0">
                    <image src="../../static/assets/img/user/lxkf.png" style="margin-right: 0; width: 34rpx; height: 34rpx" />
                    <view class="body-item-text" @tap="handleCallKf">联系客服</view>
                    <van-icon name="arrow" size="30rpx" style="margin-right: 0; margin-left: auto" />
                </view>
                <view class="body-item" @tap="Loginout">
                    <image src="../../static/assets/img/user/tcdl.png" style="margin-right: 0; width: 34rpx; height: 34rpx" />
                    <view class="body-item-text">退出登录</view>
                    <van-icon name="arrow" size="30rpx" style="margin-right: 0; margin-left: auto" />
                </view>
            </view>
        </view>
    </view>
</template>

<script>
// import vanIcon from '@vant/weapp/icon/index';
// pages/user/index.js
import util from './../../utils/util.js';
import api from './../../utils/api.js';
import { Dialog } from 'vant';
export default {
    components: {
        // vanIcon
    },
    data() {
        return {
            username: '',
            phoneNumber: '',
            plateNos: '',
            faceImageUrl: '',
            banner: [],
            list: [],
            allMoney: ' ',
            withdrawalMoney: ' ',
            balance: ' '
        };
    },
    methods: {
        //联系客服
        handleCallKf() {
            const unionId = uni.getStorageSync('unionId');
            const param = {
                type: 3,
                carOrderLogId: ''
            };
            util.request(api.call + '?carOrderLogId=' + param.carOrderLogId + '&userUnionId=' + unionId + '&type=' + param.type, 'get').then((res) => {
                if (res.code == 0) {
					if(uni.getStorageSync('weixin') == 3 || uni.getStorageSync('weixin') == 4){
						ZWJSBridge.phoneCall({
						  "corpId": res.data
						}).then(res => {
						  console.log(res)
						}).catch(err => {
						  console.log(err) 
						})
					}else{
						uni.makePhoneCall({
							phoneNumber: res.data
						}).catch((e) => {
							console.log(e);
						});
					}
                } else {
                    // wx.showToast({ title: res.msg, icon: "none" });
                }
            });
        },

        //钱包
        Gowallet() {
            uni.navigateTo({
                url: '../wallet/index'
            });
        },

        //去提现
        handleCash() {
            uni.redirectTo({
                url: '../Cash/index'
            });
        },

        handleSuggest() {
            uni.navigateTo({
                url: '../suggestion/index'
            });
        },

        //我的订单
        handleOrder() {
            uni.navigateTo({
                url: '../order/index'
            });
        },

        //修改个人信息
        handleusermessage() {
            uni.navigateTo({
                url: '../changeUser/index'
            });
        },

        //我的小区跳转
        handleoCmmunity() {
            if (this.list.length == 0) {
                // wx.navigateTo({
                //   url: "../community1/index"
                // });
                uni.switchTab({
                    url: '../community1/index'
                });
            } else if (this.list.length > 0) {
                // if (this.data.list.find(e => e.checkStatus == 0)) {
                // wx.navigateTo({
                //   url: "../community1/index"
                // });
                uni.switchTab({
                    url: '../community1/index'
                });
            }
        },

        // 登出
        Loginout() {
            Dialog.confirm({
                context: this,
                message: '确定退出账号？'
            })
                .then(() => {
                    // on confirm
                    // wx.setStorage({ key: "phoneNumber", data: this.data.value }); //手机号
                    // wx.setStorage({ key: "sms", data: this.data.sms }); //手机号
                    uni.removeStorageSync('name');
                    uni.removeStorageSync('phoneNumber');
                    uni.removeStorageSync('plateNos');
                    uni.removeStorageSync('faceImageUrl');
                    uni.removeStorageSync('status');
                    uni.removeStorageSync('sms');
                    uni.removeStorageSync('AUTHORIZATION');
                    uni.removeStorageSync('identityId');
                    uni.removeStorageSync('unionId');
                    uni.redirectTo({
                        url: '../login/index'
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },

        //我的钱包
        getmyInCome(unionId) {
            util.request(api.getMyInCome + '?unionId=' + unionId, 'get').then((res) => {
                if (res.code == 0) {
                    const allMoney = res.data.allMoney ? res.data.allMoney / 100 : 0;
                    const withdrawalMoney = res.data.withdrawalMoney ? res.data.withdrawalMoney / 100 : 0;
                    const balance = res.data.allMoney ? +res.data.allMoney / 100 : 0;
                    this.setData({
                        allMoney: allMoney,
                        withdrawalMoney: withdrawalMoney,
                        balance: balance
                    });
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none'
                    });
                }
            });
        },

        //获取个人资料
        getPersonInfoByIndentityId(value) {
            util.request(api.PersonInfoByIndentityId + '?personUnionId=' + value, 'get').then((res) => {
                if (res.code == 0) {
                    var pat = /(\d{3})\d*(\d{4})/;
                    this.setData({
                        username: res.data.name,
                        phoneNumber: res.data.phoneNumber.replace(pat, '$1****$2'),
                        plateNos: res.data ? res.data.plateNos.map((e) => e.split(',')) : ''
                    });
                } //头像转化

                if (res.data.headImageUrl) {
                    util.request(api.getEncryPath + '?path=' + res.data.headImageUrl, '', 'POST').then((res) => {
                        this.setData({
                            faceImageUrl: res
                        });
                    });
                } // 上传完成需要更新 fileList
            });
        },

        //查询关联小区
        getmyUnitList(value) {
            util.request(api.myUnitList + '?unionId=' + value, 'get').then((res) => {
                // console.log(res);
                if (res.code == 0) {
                    this.setData({
                        list: res.data
                    });
                }
            });
        },

        toPlatformRules() {
            uni.navigateTo({
                url: '../platformRules/platformRules'
            });
        },

        //常见问题
        toNormalQuestion() {
            uni.navigateTo({
                url: '../nomalQuestion/nomalQuestion'
            });
        },

        //消息中心
        messageCenter() {
            uni.showToast({
                title: '功能开发中，敬请期待',
                icon: 'none'
            });
        }
    },
    //钱包
    Gowallet() {
        uni.navigateTo({
            url: '../wallet/index'
        });
    },
    beforeMount: function () {
        // 在组件实例进入页面节点树时执行
        const unionId = uni.getStorageSync('unionId');
        this.getmyUnitList(unionId);
        this.getPersonInfoByIndentityId(unionId);
        this.getmyInCome(unionId);
    },
    destroyed: function () {
        // 在组件实例被从页面节点树移除时执行
        console.log('detached');
    }
};
</script>
<style>
@import './index.css';
</style>
